<template>
	<view class="apply-list">
		<!-- <view v-if="type != 'training'" class="header-swiper">


			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
				:duration="duration">

				<swiper-item>
					<view class="swiper-item-view" @click.stop="handleTimeDown">
						<image class="swiper-image" src="https://biapi.vaubang.cn/UploadFiles/Images/swiper-4.png"
							mode="aspectFill"></image>
					</view>
				</swiper-item>

				<swiper-item>
					<view class="swiper-item-view" @click.stop="handleApplyPublicity">
						<image class="swiper-image" src="https://biapi.vaubang.cn/UploadFiles/Images/swiper-2.png"
							mode="aspectFill"></image>
					</view>
				</swiper-item>
				<swiper-item v-if="mediaShow">
					<view class="swiper-item-view" @click.stop="handleInterview">
						<image class="swiper-image" src="https://biapi.vaubang.cn/UploadFiles/Images/swiper-3.png"
							mode="aspectFill"></image>
					</view>
				</swiper-item>

			</swiper>
		</view> -->

		<!-- 滚动提示 -->
		<!-- <uni-notice-bar show-icon scrollable :speed="50" color="#008aff" background-color="#EAF2FF"
			text="温馨提醒：积极报名，相关岗位认证通过，早享受人单酬激励！" /> -->
		<uni-notice-bar show-icon scrollable :speed="80" text="参训确认提示：根据安排的认证期数点击进入对应的期数，填写个人信息，点击提交后扫描二维码加入认证微信群！" />


		<view class="already-apply" @click="handleApplyRecord">报<br />名<br />记<br />录</view>

		<uni-load-more class="loading-class" iconType="auto" v-if="applyLoading" status="loading" color="#999999" />
		<!-- v-else -->
		<view class="apply-item" v-for="(item, index) in applyList" :key="index" @click.stop="handleApplyDetails(item)">
			<view class="apply-item-main">
				<view class="apply-item-left">
					<image class="apply-item-left-image" :src="item.img" mode="aspectFit"></image>
				</view>
				<view class="apply-item-right">
					<view class="apply-item-title">{{item.name}}</view>
					<!-- <view class="apply-item-type">类型：{{item.type}}</view> -->
					<view class="apply-item-date">集训时间：{{item.beginTime}} 至 {{item.endTime}}</view>
					<view class="apply-item-time">
						<text>报名截止时间：{{item.deadline}}</text>
					</view>
					<view class="apply-item-time">目前报名人数：{{item.signUpNum}}/{{item.largestNum}}</view>
				</view>
			</view>
			<!-- <view class="apply-item-tips">
				<text class="units">*</text>
				<text class="tips-text">{{item.tips}}</text>
			</view> -->
		</view>

		<view class="no-data-tip" v-if="applyList.length == 0">
			<image class="no-data-icon" src="../../static/no-data.png" mode="widthFix"></image>
			<text class="no-data-text">暂无报名</text>
		</view>

		<view class="empty-height"></view>
	</view>
</template>

<script>
	import apiRqs from "@/api/api-request.js";
	export default {
		data() {
			return {
				type: "",
				userOpenid: "",
				applyList: [],
				applyLoading: false,
				indicatorDots: false,
				autoplay: true,
				interval: 2500,
				duration: 500,
				mediaShow: false,
			}
		},
		onShow() {
			this.handleUserOpenid();
			this.handleMediaControl();
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type;
			}
			this.applyLoading = true;
			this.handleUserOpenid();
		},
		methods: {
			handleMediaControl() {
				apiRqs._getMediaControl().then((res) => {
					if (res.code == 200) {
						this.mediaShow = res.data;
					}
				})
			},
			// 获取用户openid
			handleUserOpenid() {
				var that = this;

				uni.login({
					provider: "weixin",
					success(loginRes) {
						let code = loginRes.code;
						uni.request({
							url: "https://bydapi.vaubang.cn/api/v1/WxOpen/FindOpenId?code=" +
								code,
							method: "post",
							header: {
								"content-type": "application/json;charset=utf-8;"
							},
							success(res) {
								console.log('用户openid', res);
								if (res.data.code == 200) {
									that.userOpenid = res.data.data.openid;
									that.handleApplyList();
								} else {
									getApp().showToast(res.data.msg);
								}
							},
							fail(err) {
								console.log(err);
							}
						})
					}
				})
			},
			// 获取报名列表
			handleApplyList() {
				var that = this;
				let rqs = {
					"pageSize": 9999,
					"pageIndex": 1,
					"orderBy": "asc"
				};
				apiRqs._getApplyList(rqs).then((res) => {
					that.applyLoading = false;
					console.log('报名列表', res);
					if (res.code == 200) {
						let applyData = JSON.parse(JSON.stringify(res.data.data));
						let newList = [];
						for (let i = 0; i < applyData.length; i++) {
							// if (applyData[i].type == '导入集训') {
							// 	applyData[i].beginTime = applyData[i].beginTime.split(" ")[0];
							// 	applyData[i].endTime = applyData[i].endTime.split(" ")[0];
							// 	applyData[i].deadline = applyData[i].deadline.split(" ")[0];
							// 	newList.push(applyData[i]);
							// }

							// 格式化日期格式
							applyData[i].beginTime = applyData[i].beginTime.split(" ")[0];
							applyData[i].endTime = applyData[i].endTime.split(" ")[0];
							applyData[i].deadline = applyData[i].deadline.split(" ")[0];
							newList.push(applyData[i]);
						}
						that.applyList = newList;
					} else {
						getApp().showToast(res.msg);
					}
				}).catch((err) => {
					console.log('err', err);
				})
			},
			handleApplyDetails(item) {
				if (item.signUpNum == item.largestNum) {
					getApp().showToast("此报名名额已满，请另选报名!");
				} else {
					uni.setStorageSync("applyInfo", item);
					uni.navigateTo({
						url: "/packageA/workbench/apply-detail?openid=" + this.userOpenid
					})
				}
			},
			handleApplyRecord() {
				uni.navigateTo({
					url: "/packageA/workbench/history-apply?openid=" + this.userOpenid
				})
			},
			onPullDownRefresh() {
				console.log('refresh');
				this.handleUserOpenid();
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1500);
			},
			onShareAppMessage() {
				return this.getShareData();
			},
			// 分享给好友
			getShareData() {
				let title = "报名通道已开启，特邀您进入报名！";
				let imageUrl = "";
				let path = '/packageA/workbench/apply-list';
				return {
					title,
					imageUrl,
					path,
				};
			},
			handleApplyPublicity() {
				uni.navigateTo({
					url: "/packageA/workbench/apply-publicity"
				})
			},
			handleInterview() {
				uni.navigateTo({
					url: "/packageA/workbench/apply-interview"
				})
			},
			handleTimeDown() {
				uni.showModal({
					title: "提示",
					content: "时间紧迫，抓紧报名啦！",
					showCancel: false,
					confirmColor: "#008aff",
				})
			},
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f5f5f5;
	}

	.apply-list {
		.header-swiper {
			width: 100%;
			height: 120px;

			.swiper {
				height: 120px !important;
			}

			.swiper-image {
				width: 100%;
				height: 120px;
			}
		}

		.movie {
			width: 100%;
			height: 100px;

			.video {
				width: 100%;
				height: 100%;
			}
		}

		.already-apply {
			position: fixed;
			right: 0px;
			bottom: 200px;
			border-top-left-radius: 6px;
			border-bottom-left-radius: 6px;
			border-top-right-radius: 0px;
			border-bottom-right-radius: 0px;
			background-color: #008aff;
			box-sizing: border-box;
			color: #fff;
			font-size: 14px;
			box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
			line-height: unset;
			border: none;
			z-index: 99;
			padding: 6px 10px;
			text-align: center;
		}

		.apply-item {
			padding: 10px;
			background-color: #fff;
			box-shadow: 0 0 8px rgba(0, 0, 0, 0.05);
			margin-top: 10px;

			&:active {
				background-color: #f1f1f1;
			}

			&:first-child {
				margin-top: 0;
			}

			.apply-item-main {
				display: flex;

				.apply-item-left {
					width: 93px;
					flex: 0 0 93px;
					height: 93px;
					border: 1px solid #f5f5f5;
					padding: 0px 4px;
					box-sizing: border-box;

					.apply-item-left-image {
						width: 100%;
						height: 100%;
					}
				}

				.apply-item-right {
					flex: 1;
					min-width: 0;
					margin-left: 5px;

					.apply-item-title {
						font-size: 15px;
						color: #000;
						margin-top: 3px;
					}

					.apply-item-type {
						font-size: 12px;
						color: #666;
						margin-top: 5px;
					}

					.apply-item-date,
					.apply-item-time {
						font-size: 12px;
						color: #666;
						margin-top: 5px;
					}

					.apply-btn {
						border: none;
						background-color: #008aff;
						color: #fff;
						width: 100px;
						height: 30px;
						text-align: center;
						line-height: 30px;
						border-radius: 4px;
						font-size: 14px;

						&:active {
							background-color: #0076DB;
						}
					}
				}
			}

			.apply-item-tips {
				font-size: 12px;
				color: #999;
				margin-top: 5px;

				.units {
					color: red;
					margin-right: 2px;
				}
			}
		}

		.no-data-tip {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			margin-top: 200rpx;

			.no-data-icon {
				width: 280rpx;
			}

			.no-data-text {
				font-size: 24rpx;
				color: #999;
				margin-top: 20rpx;
			}
		}

		.empty-height {
			width: 100%;
			height: 20px;
		}
	}
</style>